//controller JS
	var isPhone = isPhoneScreen();
	console.log("isPhone=",isPhone);

$(function() {
	$("#chooseMain").hide();
	if(isPhone){
		
		$(".mask").hide();
		$(".mainContext").hide();
		$(".chooseMainTitle").click(function(){
			$(".mask").show();
			$(".mainContext").show();
		})
		$(".Iknow").click(function(){
			$("#mask").hide();
			$(this).parent(".mainContext").hide();
	    })
	}
	$("#message_login_click").click(function() {
		if (!$(this).hasClass("active")) {
			return;
		}
		userMessageLogin();
	});
	$("#user_login_click").click(function() {
		if (!$(this).hasClass("active")) {
			return;
		}
		userLogin();
	});
});

function userMessageLogin() {
	var phone = $.trim($("#phone_input").val());
	var checkCode = $.trim($("#message_checkcode_text").val());
	if (isNull(phone)) {
		showPhoneErrMsg("请输入手机号码");
		return;
	}
	if (isNull(checkCode)) {
		showPhoneErrMsg("请输入验证码");
		return;
	}

	$.ajax({
		type : "POST",
		url : rootPath + "/userFront/accountCancel/loginbymsg",
		data : JSON.stringify({
			"login" : phone,
			"checkCode" : checkCode
		}),
		contentType : "application/json;charset=UTF-8",
		success : function(data) {
			if ("0000" == data.returnCode) {
				layer.msg("登录成功", {
					time : 1000,
					icon : 6
				});

				paint(data.returnObject);

			} else {
				showPhoneErrMsg(data.returnMessage);
			}
		}
	});
};
function userLogin() {
	var u = $("#username_input").val();
	var p = $("#password_input").val();
	var c = $("#checkcode_text").val();
	
	var isOk = true;
	if (isNull(u)) {
		showUserErrMsg("请输入用户名。");
		return;
		isOk = false;
	}
	if (isNull(p)) {
		showUserErrMsg("请输入密码。");
		return;
		isOk = false;
	}
	if (isNull(c)) {
		showUserErrMsg("请输入验证码。");
		return;
		isOk = false;
	}
	if (!isOk) {
		return;
	}
	console.log("post")
	$.ajax({
		type : "POST",
		url : rootPath + "/userFront/accountCancel/login",
		data : JSON.stringify({
			"un" : u,
			"pd" : p,
			"code" : c
		}),
		contentType : "application/json;charset=UTF-8",
		success : function(data) {
			if ("0000" == data.returnCode) {
				layer.msg("登录成功", {
					time : 1000,
					icon : 6
				});
				paint(data.returnObject);

			} else {
				showUserErrMsg(data.returnMessage);
			}
		}
	});
};

function paint(returnObject) {

	$("#cancelUid").val(returnObject.uid);
	$("#notice").hide();
	$("#chooseMain").show();


	$("#layers").remove();

	var imgSrc = "";
	if(returnObject != null && returnObject.headimgurl != null && returnObject.headimgurl != '') {
		imgSrc = rootPath + "/file/viewimg?fileName=" + (returnObject.headimgurl) + "&type=1";
	} else {
		imgSrc = "../../images/moren.png"
	}
	
	var group= $('<div class="group" id="main2"></div>');
	var fieldset = $('<fieldset class="account"></fieldset>');

	var imgLegend = $('<legend class="default"></legend>');

	var img = $('<img src="' + imgSrc +'">');
	img.appendTo(imgLegend);
	var username = "";
	if(typeof(returnObject.uname)!="undefined"){ 
		username = returnObject.uname;
	}
	var nicknameDiv = $('<div class="aWord">昵称: <span class="aWord">'
			+ username + '</span></div>');
	var phoneDiv = $('<div class="aWord">注册时间:<span class="aWord">'
			+ returnObject.cts + '</span></div>');
	fieldset.appendTo(group);
	imgLegend.appendTo(fieldset);
	nicknameDiv.appendTo(fieldset);
	phoneDiv.appendTo(fieldset);
	
	group.appendTo($("#accountCancel"));
	
	//注销理由
	var reason = $("<div class='reasonDiv'><div class='current-next'><span class='info'>*</span>注销理由:</div><textarea id='reason' rows='10' cols='10' style='vertical-align:top;'></textarea></div>");
	reason.appendTo($("#accountCancel"));

	// 注销按钮
	var cancelButton = $('<div class="commitBtn"><input type="button" id="cancel" value="申请注销" onclick="cancel();" ></div>');
	cancelButton.appendTo($('#contentInfo'));
	if(isPhone){
		$(".account").show();
		/*$(".chooseMainTitle").click(function(){
			$(".mask").show();
			$(".mainContext").show();
		})
		$(".Iknow").click(function(){
			$("#mask").hide();
			$(this).parent(".mainContext").hide();
	    })*/
	}
};

function cancel(){
	var cancelUid = $("#cancelUid").val();
	var reason = $("#reason").val();
	if(isNull(cancelUid)){
		layer.msg("数据错误，刷新重试", {
			time : 1000,
			icon : 2
		});
		return;
	}
	if(isNull(reason) || isNull($.trim(reason))) {
		layer.msg("请填写注销理由", {
			time : 1000,
			icon : 2
		});
		return;
	}
	if(reason.length > 200) {
		layer.msg("注销理由输入过长,请精简", {
			icon : 2
		});
		return;
	}
	$.ajax({
		type : "POST",
		url : rootPath + "/userFront/cancelApplication",
		data : JSON.stringify({
			"cancelUid" : cancelUid,
			"reason" : reason
		}),
		contentType : "application/json;charset=UTF-8",
		success : function(res) {
			if ("0000" == res.returnCode) {
				layer.msg("申请成功", {icon : 6,time: 1000},function(){
					parent.$("#content").prop("src","securitySetting.html");
				});
			} else {
				layer.msg(res.returnMessage, {icon : 2}); 
			}
		}
	});
};